home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / beveled-button.scm < prev    next >
Encoding:
Text File  |  2005-06-30  |  5.0 KB  |  157 lines

  1. ; The GIMP -- an image manipulation program
  2. ; Copyright (C) 1995 Spencer Kimball and Peter Mattis
  3. ; Button00 --- create a simple beveled Web button
  4. ; Copyright (C) 1997 Federico Mena Quintero
  5. ; federico@nuclecu.unam.mx
  6. ; This program is free software; you can redistribute it and/or modify
  7. ; it under the terms of the GNU General Public License as published by
  8. ; the Free Software Foundation; either version 2 of the License, or
  9. ; (at your option) any later version.
  10. ; This program is distributed in the hope that it will be useful,
  11. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ; GNU General Public License for more details.
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program; if not, write to the Free Software
  16. ; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. ; ************************************************************************
  18. ; Changed on Feb 4, 1999 by Piet van Oostrum <piet@cs.uu.nl>
  19. ; For use with GIMP 1.1.
  20. ; All calls to gimp-text-* have been converted to use the *-fontname form.
  21. ; The corresponding parameters have been replaced by an SF-FONT parameter.
  22. ; ************************************************************************
  23.  
  24.  
  25. (define (text-width extents)
  26.   (car extents))
  27.  
  28. (define (text-height extents)
  29.   (cadr extents))
  30.  
  31. (define (text-ascent extents)
  32.   (caddr extents))
  33.  
  34. (define (text-descent extents)
  35.   (cadr (cddr extents)))
  36.  
  37. (define (blend-bumpmap img
  38.                drawable
  39.                x1
  40.                y1
  41.                x2
  42.                y2)
  43.   (gimp-edit-blend drawable FG-BG-RGB-MODE DARKEN-ONLY-MODE
  44.            GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE
  45.            FALSE 0 0 TRUE
  46.            x1 y1 x2 y2))
  47.  
  48. (define (script-fu-button00 text
  49.                 size
  50.                 font
  51.                 ul-color
  52.                 lr-color
  53.                 text-color
  54.                 padding
  55.                 bevel-width
  56.                 pressed)
  57.   (let* ((text-extents (gimp-text-get-extents-fontname text
  58.                           size
  59.                           PIXELS
  60.                           font))
  61.      (ascent (text-ascent text-extents))
  62.      (descent (text-descent text-extents))
  63.  
  64.      (img-width (+ (* 2 (+ padding bevel-width))
  65.                (text-width text-extents)))
  66.      (img-height (+ (* 2 (+ padding bevel-width))
  67.             (+ ascent descent)))
  68.  
  69.      (img (car (gimp-image-new img-width img-height RGB)))
  70.  
  71.      (bumpmap (car (gimp-layer-new img
  72.                        img-width img-height RGBA-IMAGE
  73.                        "Bumpmap" 100 NORMAL-MODE)))
  74.      (gradient (car (gimp-layer-new img
  75.                     img-width img-height RGBA-IMAGE
  76.                     "Gradient" 100 NORMAL-MODE))))
  77.  
  78.     (gimp-context-push)
  79.  
  80.     (gimp-image-undo-disable img)
  81.  
  82.     ; Create bumpmap layer
  83.     
  84.     (gimp-image-add-layer img bumpmap -1)
  85.     (gimp-context-set-foreground '(0 0 0))
  86.     (gimp-context-set-background '(255 255 255))
  87.     (gimp-edit-fill bumpmap BACKGROUND-FILL)
  88.  
  89.     (gimp-rect-select img 0 0 bevel-width img-height CHANNEL-OP-REPLACE FALSE 0)
  90.     (blend-bumpmap img bumpmap 0 0 (- bevel-width 1) 0)
  91.  
  92.     (gimp-rect-select img 0 0 img-width bevel-width CHANNEL-OP-REPLACE FALSE 0)
  93.     (blend-bumpmap img bumpmap 0 0 0 (- bevel-width 1))
  94.  
  95.     (gimp-rect-select img (- img-width bevel-width) 0 bevel-width img-height CHANNEL-OP-REPLACE FALSE 0)
  96.     (blend-bumpmap img bumpmap (- img-width 1) 0 (- img-width bevel-width) 0)
  97.  
  98.     (gimp-rect-select img 0 (- img-height bevel-width) img-width bevel-width CHANNEL-OP-REPLACE FALSE 0)
  99.     (blend-bumpmap img bumpmap 0 (- img-height 1) 0 (- img-height bevel-width))
  100.  
  101.     (gimp-selection-none img)
  102.  
  103.     ; Create gradient layer
  104.  
  105.     (gimp-image-add-layer img gradient -1)
  106.     (gimp-context-set-foreground ul-color)
  107.     (gimp-context-set-background lr-color)
  108.  
  109.     (gimp-edit-blend gradient FG-BG-RGB-MODE NORMAL-MODE
  110.              GRADIENT-LINEAR 100 0 REPEAT-NONE FALSE
  111.              FALSE 0 0 TRUE
  112.              0 0 (- img-width 1) (- img-height 1))
  113.  
  114.     (plug-in-bump-map 1 img gradient bumpmap
  115.               135 45 bevel-width 0 0 0 0 TRUE pressed 0)
  116.  
  117.     ; Create text layer
  118.  
  119.     (gimp-context-set-foreground text-color)
  120.     (let ((textl (car (gimp-text-fontname
  121.                img -1 0 0 text 0 TRUE size PIXELS font))))
  122.       (gimp-layer-set-offsets textl
  123.                   (+ bevel-width padding)
  124.                   (+ bevel-width padding descent)))
  125.  
  126.     ; Done
  127.  
  128.     (gimp-selection-none img)
  129.     (gimp-image-undo-enable img)
  130.     (gimp-display-new img)
  131.  
  132.     (gimp-context-pop)))
  133.  
  134. (script-fu-register "script-fu-button00"
  135.             _"Simple _Beveled Button..."
  136.             "Simple beveled button"
  137.             "Federico Mena Quintero"
  138.             "Federico Mena Quintero"
  139.             "June 1997"
  140.             ""
  141.             SF-STRING     _"Text"               "Hello world!"
  142.             SF-ADJUSTMENT _"Font size (pixels)" '(16 2 100 1 1 0 1)
  143.             SF-FONT       _"Font"               "Sans"
  144.             SF-COLOR      _"Upper-left color"   '(0 255 127)
  145.             SF-COLOR      _"Lower-right color"  '(0 127 255)
  146.             SF-COLOR      _"Text color"         '(0 0 0)
  147.             SF-ADJUSTMENT _"Padding"            '(2 1 100 1 10 0 1)
  148.             SF-ADJUSTMENT _"Bevel width"        '(4 1 100 1 10 0 1)
  149.             SF-TOGGLE     _"Pressed"            FALSE)
  150.  
  151. (script-fu-menu-register "script-fu-button00"
  152.              _"<Toolbox>/Xtns/Script-Fu/Buttons")
  153.